import { _decorator, Component, MeshRenderer, Node, v3 } from 'cc';
const { ccclass, property } = _decorator;
/**
 * 隐藏网格最大-最小位置，防止被相机剔除
 * 同类型的网格 只需要设置一次
 */
@ccclass('HideMeshMaxPos')
export class HideMeshMaxPos extends Component {
    @property
    scale = 4;

    onLoad() {
        const meshRecs: { [name: string]: boolean } = {};
        for (let i = 0; i < this.node.children.length; i++) {
            const e = this.node.children[i];
            // 放大网格的最大最小值 防止相机剔除时 阴影提前消失
            const msr = e.getComponent(MeshRenderer);
            if (msr) {
                const id = msr.mesh.uuid;
                if (!meshRecs[id]) {
                    msr.mesh.struct.maxPosition = v3(msr.mesh.struct.maxPosition).multiplyScalar(this.scale);
                    msr.mesh.struct.minPosition = v3(msr.mesh.struct.minPosition).multiplyScalar(this.scale);
                    meshRecs[id] = true;
                    // console.log('建筑 mesh:', id);
                }
            }
        }
    }

}


